{% for cat in page.category %}
  {% if cat == 'needs-review' %}
    <div class="row">
      <div class="col-lg-12">
        {% alert info %}
This document has been marked `needs-review`. The following information may be outdated or may no longer apply to the latest Marlin.
        {% endalert %}
      </div>
    </div>
  {% endif %}
{% endfor %}

<div class="row meta">
  <div class="col-lg-12">
    <p class="text-right pull-right visible-lg-block hidden-print small custom-pt25">
      {% assign authors = gcode.author | append: ',' | append: gcode.contrib | replace: ' ', '' | split: ',' %}
      {% if authors %}
        {% for author in authors %}
          <a href="https://github.com/{{ author }}" data-toggle="tooltip" data-placement="bottom" title="Visit {{ author }}'s profile on Github">{% avatar user=author size=30 %}</a>
        {% endfor %}
      {% endif %}
    </p>

    <h1 class="custom-no-margin-bottom">
      {% for code in gcode.codes %}
        {{ code }}{% if forloop.last != true %}, {% endif %}
      {% endfor %} - {{ gcode.title }}
    </h1>

    {% if gcode.experimental %}
      <span class="label label-warning"><span data-toggle="tooltip" data-placement="bottom" title="Experimental feature"><i class="fa fa-flask" aria-hidden="true"></i></span></span>
    {% endif %}

    {% if gcode.since %}
      <span class="label label-success"><span data-toggle="tooltip" data-placement="bottom" title="Available since"><i class="fa fa-code" aria-hidden="true"></i>
      {{ gcode.since }}</span></span>
    {% endif %}

    {% if gcode.group %}
      <span class="label label-default"><i class="fa fa-tags" aria-hidden="true"></i>
      {{ gcode.group }}</span>
    {% endif %}

    {% if gcode.brief %}
      <span class="label label-primary"><i class="fa fa-pencil-square" aria-hidden="true"></i> {{gcode.brief}}</span>
    {% endif %}

    {% if gcode.requires %}
      {% assign list = (gcode.requires | split: ',') %}
      {% for item in list %}
        <span class="label label-requires"><code>{{item}}</code></span>
      {% endfor %}
    {% endif %}
  </div>
</div>

<div class="row long">
  <div class="col-lg-12">
    {% if gcode.long %}
      {% for line in gcode.long %}
        {{ line | markdownify }}
        <hr />
      {% endfor %}
    {% endif %}
  </div>
</div>

<div class="row usage" id="usage-{{ gcode.tag }}">
  <div class="col-lg-12">
    <h2>Usage</h2>
    <code>{{ gcode.codes[0] }}
      {% if gcode.parameters %}
        {% assign list = ('' | split: '|') %}
        {% for parm in gcode.parameters %}
          {% if parm.tag %}
            {% assign list = list | push: parm %}
          {% endif %}
        {% endfor %}

        {% if list.size > 0 %}
          {% assign list = (list | sort: 'tag') %}
          {% for parm in list %}
            <span data-toggle="tooltip" data-placement="bottom" data-original-title="{{ parm.description }}">
              {% if parm.optional == true%}&#x5B;{% endif %}<!--
              -->{{ parm.tag }}<!--
              -->{% if parm.values.size > 0 %}<!--
                -->{% if parm.values.size == 1 %}<!--
                  -->{% assign pv = parm.values[0] %}<!--
                  -->{% if pv.optional == true%}&#x5B;{% else %}&lt;{% endif %}<!--
                  -->{% if pv.tag %}<!--
                    -->{{ pv.tag }}<!--
                    -->{% if pv.unit %}<!--
                      --> in {{ pv.unit }}<!--
                    -->{% endif %}<!--
                  -->{% elsif pv.unit %}<!--
                    -->{{ pv.unit }}<!--
                  -->{% elsif pv.type %}<!--
                    -->{{ pv.type }}<!--
                  -->{% else %}<!--
                    -->Unknown<!--
                  -->{% endif %}<!--
                  -->{% if pv.optional == true%}&#x5D;{% else %}&gt;{% endif %}<!--
                -->{% else %}<!--
                  -->&lt;<!--
                  -->{% for pv in parm.values %}<!--
                    -->{{ pv.tag }}<!--
                    -->{% if forloop.last != true %}<!--
                      -->&#x7C;<!--
                    -->{% endif %}<!--
                  -->{% endfor %}<!--
                  -->&gt;<!--
                -->{% endif %}<!--
              -->{% endif %}<!--
              -->{% if parm.optional == true%}&#x5D;{% endif %}
            </span>
          {% endfor %}
        {% endif %}
      {% endif %}
    </code>
  </div>
</div>

{% if gcode.parameters %}
  {% assign list = ('' | split: '|') %}
  {% for parm in gcode.parameters %}
    {% if parm.tag %}
      {% assign list = list | push: parm %}
    {% endif %}
  {% endfor %}

  {% if list.size > 0 %}
    <div class="row params">
      <div class="col-lg-12">
        <div class="table-responsive">
          <p>
            <table class="table">
              <thead>
                <tr>
                  <th>Argument</th>
                  <th>Description</th>
                </tr>
              </thead>
              <tbody>
                {% assign list = (list | sort: 'tag') %}
                {% for parm in list %}
                  <tr>
                    <td class="arg"><code>
                      {% if parm.optional == true%}&#x5B;{% endif %}<!--
                      -->{{ parm.tag }}<!--
                      -->{% if parm.values.size > 0 %}<!--
                        -->{% if parm.values.size == 1 %}<!--
                          -->{% assign pv = parm.values[0] %}<!--
                          -->{% if pv.optional == true%}&#x5B;{% else %}&lt;{% endif %}<!--
                          -->{% if pv.tag %}<!--
                            -->{{ pv.tag }}<!--
                            -->{% if pv.unit %}<!--
                              --> in {{ pv.unit }}<!--
                            -->{% endif %}<!--
                          -->{% elsif pv.unit %}<!--
                            -->{{ pv.unit }}<!--
                          -->{% elsif pv.type %}<!--
                            -->{{ pv.type }}<!--
                          -->{% else %}<!--
                            -->Unknown<!--
                          -->{% endif %}<!--
                          -->{% if pv.optional == true%}&#x5D;{% else %}&gt;{% endif %}<!--
                        -->{% else %}<!--
                          -->&lt;<!--
                          -->{% for pv in parm.values %}<!--
                            -->{{ pv.tag }}<!--
                            -->{% if forloop.last != true %}<!--
                              -->&#x7C;<!--
                            -->{% endif %}<!--
                          -->{% endfor %}<!--
                          -->&gt;<!--
                        -->{% endif %}<!--
                      -->{% endif %}<!--
                      -->{% if parm.optional == true%}&#x5D;{% endif %}
                    </code></td>
                    <td>
                      {{ parm.description | markdownify }}
                      {% if parm.values.size > 0 %}
                        <ul class="param-desc-list">
                          {% for pv in parm.values %}
                            {% if pv.description %}
                              <li>
                                <code>{{ parm.tag }}{{ pv.tag }}</code>: {{ pv.description | markdownify }}
                              </li>
                            {% endif %}
                          {% endfor %}
                        </ul>
                      {% endif %}
                    </td>
                  </tr>
                {% endfor %}
              </tbody>
            </table>
          </p>
        </div>
      </div>
    </div>
  {% endif %}
{% endif %}

{% if gcode.notes %}
  <div class="row notes">
    <div class="col-lg-12">
      <h2>Notes</h2>
        {% for line in gcode.notes %}
          {{ line | markdownify }}
        {% endfor %}
    </div>
  </div>
{% endif %}

{% if gcode.examples %}
  {% assign ex = gcode.examples %}
  {% assign plural = "s" %}
{% else %}
  {% if gcode.example %}
    {% assign ex = gcode.example %}
    {% assign plural = "" %}
  {% else %}
    {% assign ex = [] %}
  {% endif %}
{% endif %}

{% if ex %}
  <div class="row examples">
    <div class="col-lg-12">
      <h2>Example{{ plural }}</h2>
      {% for example in ex %}
        {% if example.pre %}
          {% for line in example.pre %}
            {{ line | markdownify }}
          {% endfor %}
        {% endif %}
        {% highlight gcode %}{% for line in example.code %}{{ line }}
{% endfor %}{% endhighlight %}
        {% if example.post %}
          <div class="post">
            {% for line in example.post %}
              {{ line | markdownify }}
            {% endfor %}
          </div>
        {% endif %}
      {% endfor %}
    </div>
  </div>
{% endif %}
